<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->params['static'].'assets/js/validateEngine/jquery.validationEngine.min.js',2); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->params['static'].'assets/js/validateEngine/jquery.validationEngine-zh_CN.js',2); ?>
<?php Yii::app()->clientScript->registerCssFile(Yii::app()->params['static'].'assets/css/validationEngine.jquery.css'); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->params['static'].'assets/js/bootbox.min.js',2); ?>
<div class="page-header">
							<h1>
							新建试卷
							</h1>
</div>
<div class="row">
	<div class="col-xs-12">
	  <div class="row">
						<div class="widget-box">
						<div class="widget-header widget-header-small">
								<h5 class="lighter">新建问卷</h5>
						</div>

						<div class="widget-body">
								<div class="widget-main">
                              <div class="table-responsive">
											<table  class="table table-striped table-bordered table-hover">
												<thead>
													<tr>
														
														<th>调查问卷名称</th>
														<th>
															<i class="icon-time bigger-110"></i>
															添加时间
														</th>
														
														<th>描述</th>
														<th>状态</th>
														<th>参加人数</th>
														<th>题目数目</th>
														<th>操作</th>
													</tr>
												</thead>

												<tbody>
												<?php
												  foreach($surs as $s){
													  $edit = '';
													  if($s->ispost == '0'){
													     $con = '<span class="label label-sm label-warning"><i class="icon-spinner"></i>&nbsp未发布</span>';
														 $edit = '<a target="_blank" href="'.Yii::app()->CreateUrl('survey/addsurvey',array('id'=>$s->surveyId)).'">
															   <button class="btn btn-xs btn-warning" data-rel = "tooltip" data-original-title = "编辑试卷">
																	<i class="icon-edit bigger-120"></i>
																</button>
                                                                </a>';
													  }else if($s->ispost == '1'){
														   $con = '<span class="label label-sm label-success"><i class="icon-spinner"></i>&nbsp已发布</span>';
														  
													  }
													  
													 echo '
													<tr id="'.$s->surveyId.'">
														<td>
															<a href="#">'.$s->name.'</a>
														</td>
													
														<td>'.$s->addtime.'</td>
														<td>
														  <span display-detail-id="'.$s->surveyId.'" style="display:none;">'.$s->detail.'</span>
															<button class="btn btn-sm btn-info" detail-id="'.$s->surveyId.'">
																详情
															</button>
														</td>
														<td>'.$con.'</td>
														<td>'.$s->attendnum.'</td>
														<td>'.$s->questionnum.'</td>

														
														<td>
															<div class="visible-md visible-lg hidden-sm hidden-xs btn-group">
												               '.$edit.'
																<a>
																<button class="btn btn-xs btn-danger" data-rel = "tooltip" data-original-title = "删除试卷" delete-id="'.$s->surveyId.'">
																	<i class="icon-trash bigger-120"></i>
																</button>
																</a>
															</div>
															
														</td>
													</tr>';
												  }
                                                   ?>
												</tbody>
											</table>
										</div><!-- /.table-responsive -->
										<div class="col-xs-12" style="text-align:center">
										     <?php 
											 $this->widget('CLinkPager',array( 
													'htmlOptions'=>array('class'=>'pagination'),
													'cssFile'=>false,
													'header'=>'',    
													'firstPageLabel' => '首页',    
													'lastPageLabel' => '末页',    
													'prevPageLabel' => '上一页',    
													'nextPageLabel' => '下一页',    
													'pages' => $pages,    
													'maxButtonCount'=>13    
												)    
											);    
												
										?>
							       </div>
						</div>
				</div>
		 </div>
	</div>
						
<hr>

	<div class="row">
				<div class="widget-box">
						<div class="widget-header widget-header-small">
								<h5 class="lighter">新建问卷</h5>
						</div>

						<div class="widget-body">
								<div class="widget-main">
									<form class="form-horizontal" role="form" method="post" action="<?php echo Yii::app()->createUrl('survey/newsurvey'); ?>">
                                    <div class="form-group">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-6">问卷名称：</label>

										<div class="col-sm-4">
											<input  type="text" class="form-control validate[required]" placeholder="问卷名称" title="" name="name">
											
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-6">问卷描述：</label>

										<div class="col-sm-4">
											<textarea col="10" rows="5" class="form-control validate[required]" name="detail"  placeholder="问卷描述"></textarea>
											
										</div>
									</div>
									<div class="space-4" id="add"></div>
                                   <div class="clearfix form-actions">
										<div class="col-md-offset-4 col-md-8">
											<button class="btn btn-info" type="submit">
												<i class="icon-ok bigger-110"></i>
												提交
											</button>
											</div>
									</div>

								
					            </form>
							</div>
						</div>
				</div>                   
					
 
		</div>
	</div>				
</div>
<script type="text/javascript">
   jQuery(function($){
	   <?php
	       if(Yii::app()->user->hasFlash('add')){
			   echo 'bootbox.alert("'.Yii::app()->user->getFlash('add').'",function(){});';
			   
		   }
	   ?>
	   //post a survey
	    <?php
	       if(Yii::app()->user->hasFlash('post')){
			   echo 'bootbox.alert("'.Yii::app()->user->getFlash('post').'",function(){});';
			   
		   }
	   ?>
	   
	   
	    $('[detail-id]').on("click",function(){
			var id = $(this).attr('detail-id');
			bootbox.alert($("[display-detail-id = "+id+"]").html(),function(){
				
				
			});

		  
		   
	   });
	   
	   // delete a survey
	   $('[delete-id]').on('click',function(){
		    var id = $(this).attr('delete-id');
			bootbox.confirm('删除之后，所有学生添加的答题记录及问卷统计都将会被删除<br>确定要删除吗？',function(result){
				if(result){
					$.post("<?php echo Yii::app()->createUrl('survey/delete'); ?>",{'surveyId':id},function(data){
						data = $.parseJSON(data);
						bootbox.alert(data['msg'],function(){
						    if(data['code'] == '200'){
								$('#'+id).fadeToggle('800','linear',function(){
									
									$(this).remove();
								});
								
							}	
						});
						
					});
					
				}
				
			});
		   
	   });
	   
	     //begin the validate
		  $(".form-horizontal").validationEngine("attach",{ 
				promptPosition:"topRight", 
				scroll:true,
				validateNonVisibleFields:false,
		  }); 
   })
</script>